/* Author: David McCoy dave.mccoy@cospandesign.com
 *
 *     This file is part of DLCM\SubServ.
 *
 *  DLCM\SubServ is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  DLCM\SubServ is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with DLCM\SubServ.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * UDPGenerator.java
 *
 * Generator a UDP provider
 * 
 */

package com.cospandesign.gui.providers.udp;

import com.cospandesign.gui.providers.ProviderGuiGenerator;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import lcm.lcm.LCM;


public class UDPGenerator extends ProviderGuiGenerator {


   public boolean LocalHostFlag = false;
   public String IPString;
   public String PortNumber;
   public Integer TTL;


   public UDPGenerator (){
   }

   private PropertyChangeSupport support = new PropertyChangeSupport(this);

   public void addPropertyChangeListener(PropertyChangeListener listener ) {
      this.support.addPropertyChangeListener( listener );
   }

   public void removePropertyChangeListener(PropertyChangeListener listener ) {
      this.support.removePropertyChangeListener( listener );
   }

   public boolean isLocalHostFlag() {
        return LocalHostFlag;
    }

   public void setLocalHostFlag(boolean LocalHostFlag) {
        boolean old  = this.LocalHostFlag;
        this.LocalHostFlag = LocalHostFlag;
        support.firePropertyChange("LocalHostFlag", old, LocalHostFlag);
    }


   public void setIPString(String IPString) {
        this.IPString = IPString;
    }

   public String getPortNumber(){
       return PortNumber;
   }
   
   public void setPortNumber(String PortNumber){
       String old = this.PortNumber;
       this.PortNumber = PortNumber;
       support.firePropertyChange("Port Number", old, PortNumber);
   }

   public Integer getTTL(){
        return TTL;
    }

   public void setTTL(Integer TTL){
        Integer old = TTL;
        this.TTL = TTL;
        support.firePropertyChange("TTL", old, TTL);
    }

    @Override
    public HashMap<String, String> getProviderVariables() {
        HashMap<String, String> ProviderMap = new HashMap<String, String>();

        ProviderMap.put("protocol", "udpm");
        //TODO Fix Network
        ProviderMap.put("network", IPString + ":" + getPortNumber());
        //ProviderMap.put("network", "192.168.1.101:" + getPortNumber());
        ProviderMap.put("ttl", "1"/* getTTL().toString()*/);

        return ProviderMap;
    }



   @Override
   public LCM GenerateProvider() {
        LCM lcm = null;
        try {
            lcm = new LCM("");
        } catch (IOException ex) {
            Logger.getLogger(UDPGenerator.class.getName()).log(Level.SEVERE, null, ex);
        }

        return lcm;

    }


}
